# coding:UTF-8
# ________________________
# Project_Name:pythonProject
# File_Name:Administrator
# Author:Administrator
# Date_Time:2022/4/21 15:25
# Description:
# ________________________
# _*_ coding: UTF-8 _*_
# @Time     : 2022/4/21 15:19
# @Author   : Li Jie
# @Site     : http://www.cdtest.cn/
# @File     : 元素的基本操作.py
# @Software : PyCharm

from selenium import webdriver
import time
from selenium.webdriver.common.by import By


def foo1():
    """
    模拟键盘输入sendkeys()
    清空输入框clear()
    :return: None
    """
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get("https://www.baidu.com/")

    driver.find_element(By.NAME, "wd").clear()
    driver.find_element(By.NAME, "wd").send_keys("51放假安排")  # 模拟键盘输入
    time.sleep(3)

    # 在输入框输入之前一定先清空一次
    driver.find_element(By.NAME, "wd").clear()  # 清空input输入框，只针对<input>
    driver.find_element(By.NAME, "wd").send_keys("猫的图片")
    time.sleep(5)

    driver.quit()

def foo2():
    """

    :return: None
    """
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get("https://www.baidu.com/")
    el = driver.find_element(By.XPATH,'//*[@id="s-top-left"]/a[1]')
    #获取新闻的herf属性
    att = el.get_attribute("href")
    print(att)
    #获取元素文本text
    text=el.text
    print(text)

    driver.quit()


if __name__ == "__main__":
    # foo1()
    foo2()